package com.e.dianshang.controller;

import com.e.dianshang.pojo.GetTicket;
import com.e.dianshang.service.GetTicketService;
import com.e.dianshang.service.OrderService;
import com.e.dianshang.service.TicketService;
import com.e.dianshang.utils.BusinessException;
import com.e.dianshang.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author Tian同學
 * @Date 2020/11/9 17:58
 * @Version 1.0
 */
@RestController
@RequestMapping("/tkt")
@Api(value = "优惠券",tags = "品牌下优惠券的api")
public class TicketController {

    @Resource
    TicketService ticketService;

    @Resource
    GetTicketService getTicketService;

    @GetMapping("/getTkt")
    @ApiOperation(value = "查看该商品优惠券接口",httpMethod = "GET")
    @ApiImplicitParam(name = "brandID",value = "品牌id",required = true,dataType = "int",paramType = "query")
    public Map getTkt(@RequestParam("brandID") Integer brandID,@RequestParam("openid") String openid) throws BusinessException {

        JsonResult jsonResult=new JsonResult();

        List<Map> tkt = ticketService.getTkt(brandID);

        List<GetTicket> tktBrand = getTicketService.getTktBrand(openid, brandID);
        if (!tkt.isEmpty()){
            jsonResult.setCode("0");
            jsonResult.put("tkt",tkt);
            jsonResult.put("getTkt",tktBrand);
        }else {
            throw new BusinessException("还没有优惠券哟！");
        }

        return jsonResult.getValues();

    }

}
